function convertToStarsArray(stars) {
  let num = stars.toString().substring(0, 1)
  let array = []
  for (let i=1; i<=5; i++) {
    if (i<=num) {
      array.push(1)
    } else {
      array.push(0)
    }
  }
  return array
}

function http (url, callBack) {
  wx.request({
    url,
    data: {},
    method: 'GET',
    header: {
      "content-Type": ""
    },
    success (res) {
      callBack(res.data)
    },
    fail (error) {
      console.log('调用失败')
      console.log(error)
    }
    // complete () {

    // }
  })
}

function convertToCastString(casts) {
  let castsjoin = ""
  for (let idx in casts) {
    castsjoin = castsjoin + casts[idx].name + " / "
  }
  return castsjoin.substring(0, castsjoin.length-2)
}

function convertToCastInfos(casts) {
  let castsArray = []
  for (let idx in casts) {
    let cast = {
      img: casts[idx].avatars.large ? casts[idx].avatars.large : "",
      name: casts[idx].name
    }
    castsArray.push(cast)
  }
  return castsArray
}

module.exports = {
  convertToStarsArray,
  http,
  convertToCastString,
  convertToCastInfos
}
